
using AutoMapper;
using Domain.Models;
using IRepository;
using IServices;
using Services.Base;
using System.Collections.Generic;
using System.Linq;
using ViewModel.EmployeeModel;

namespace Services
{
    public class EmployeeService:BaseService<Employee>,IEmployeeService
    {
        protected readonly IEmployeeRepository employeeRepository;

        public EmployeeService(IEmployeeRepository employeeRepository,IMapper mapper):base(mapper)
        {
            this.employeeRepository = employeeRepository;
            base.baseRepository = employeeRepository;
        }

        public int CreateEmployee(CreateEmployeeModel model)
        {
            var entity = mapper.Map<Employee>(model);
            var result = this.employeeRepository.Add(entity);
            if (result > 0)
            {
                return entity.Id;
            }
            return -1;
        }

        public IEnumerable<EmployeeBase> GetEmployees()
        {
            return this.employeeRepository.Query().Select(x => new EmployeeBase
            {
                Id = x.Id,
                EmployeeNo = x.EmployeeNo,
                Gender = x.Gender,
                Name = x.Name
            });
        }
    }

}